package com.zzs.restweb.util;

import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Properties;

/**
 * @Description TODO
 * @Author 张智顺
 * @Date 2020/9/17-21:12
 */
@Component
public class StanfordCoreNLPBean {

    private StanfordCoreNLP pipeline;

    public StanfordCoreNLPBean() {
        getStanfordCoreNLP();
    }

    public StanfordCoreNLP getStanfordCoreNLP() {
        if (null == pipeline) {
            synchronized (Properties.class) {
                if (null == pipeline) {
                    try {
                        Properties props = PropertiesSingleton.getInstance();
                        props.load(this.getClass().getResourceAsStream("/StanfordCoreNLP-chinese.properties"));
                        pipeline = new StanfordCoreNLP(props);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        return pipeline;
    }

}
